package com.nchu.controller;

import com.nchu.VO.StudentVO;
import com.nchu.common.util.PageResult;
import com.nchu.common.util.R;
import com.nchu.entity.Student;
import com.nchu.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yaojie
 * @since 2025-01-07
 */
@RestController
@RequestMapping("/student")
@CrossOrigin //配置跨域
public class StudentController {
    @Autowired
    private IStudentService studentService;

    // 学生列表
    @GetMapping("/list")
    public R getStudent() {
        System.out.println("调用了！");
        return R.ok().data("list",studentService.list());
    }

    // 分页查询
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable("page") Integer page,
                        @PathVariable("pageSize") Integer pageSize) {
        PageResult<Student> pr = studentService.findByPage(page,pageSize);
        return R.ok().data("pr",pr);
    }
    // 条件带分页查询
    @PostMapping("/search/{page}/{pageSize}")
    public R search(@PathVariable("page") Integer page,
                    @PathVariable("pageSize") Integer pageSize,
                    @RequestBody(required = false) StudentVO vo){
        PageResult<Student> pr = studentService.search(page,pageSize,vo);
        return R.ok().data("pr",pr);
    }
}
